<%-- 
    Document   : verEstadisticas
    Created on : 04/12/2013, 01:15:56 AM
    Author     : chonabook
--%>

<%@page import="Servidor.DataEstadistica"%>
<%@page import="Servidor.DataJuego"%>
<%@page import="Servidor.DataReclamo"%>
<%@page import="Servidor.DataPerfil"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.List"%>
<%@include file= "cargarLogica.jsp" %>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="es">
    
<head>
	<title>TPlay Market - Tienda de Juegos On-Line</title>
	<meta charset="utf-8"/>
	<meta name="description" content="Bienvenido a TPlay Market, tienda de Juegos On-Line"/>
	<meta name="viewport" content="width=device-width, initial-scale=1"/>
	<link rel="shortcut icon" type="image/xicon" href="favicon.ico"/>
	<link rel="stylesheet" type="text/css" href="css/tplay_style.css"/>
        <script type = "text/javascript" src = "js/JQuery2.0.3.js"></script>
        <script type = "text/javascript" src = "js/buscarJuegos.js"></script>
	<!-- [if lt IE 9]>
		<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
	<![enif]-->
    <!--Load the AJAX API-->
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">

        <%

            String dataEstadistica = new String();

            if(session.getAttribute("usuario") == null){
                response.setHeader("Refresh", "3;url=inicioSesion.jsp");

            }else{
                
                DataPerfil dp = (DataPerfil)session.getAttribute("usuario");
                if(dp.getTipoperfil().equals("[CLIENTE]")){
                
                    dataEstadistica = "<h4>Udsted no es desarrollador!!</h4>";
                    dataEstadistica = dataEstadistica.concat("<h4>Arranca para la fing!! Manco!!</h4>");
                    response.setHeader("Refresh", "3;url=index.jsp");
                    
                }else{
        %>

      // Load the Visualization API and the piechart package.
      google.load('visualization', '1.0', {'packages':['corechart']});

      // Set a callback to run when the Google Visualization API is loaded.
      google.setOnLoadCallback(drawChart);

      // Callback that creates and populates a data table,
      // instantiates the pie chart, passes in the data and
      // draws it.
      function drawChart() {

        // Create the data table.
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Juegos');
        data.addColumn('number', 'Ganancia$');
        <%
                    try{

                        dataEstadistica = "<h4>Estadisticas de: " + dp.getNick() + "</h4>";
                        DataEstadistica de = ip.obtenerEstadisticaPIE(dp.getNick());

                        if(!de.getDatosX().isEmpty()){

                            for(int i = 0; i <= de.getDatosX().size() - 1; i++){

                                %>
        data.addRows([['<%= de.getDatosX().get(i) %>', <%= de.getDatosY().get(i) %>]]);

        // Set chart options
        var options = {'title':'Ganancias por juego de <%= dp.getNick() %>.',
                       'width':800,
                       'height':350};

        // Instantiate and draw our chart, passing in some options.
        var chart = new google.visualization.PieChart(document.getElementById('pie'));
        chart.draw(data, options);
        
                                <%
                            }
                            
                        }else{

                            dataEstadistica = "<h4>No tiene compras registradas!!</h4>";
                            dataEstadistica = dataEstadistica.concat("<h4>No es posible sacar informacion Estadistica!!</h4>");
                            response.setHeader("Refresh", "3;url=index.jsp");                    

                        }

                    }catch(Exception e){

                        dataEstadistica = dataEstadistica.concat(e.getMessage());

                    }

                }
            }

         %>        

      }
    </script>  
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
          
          
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Meses');
        data.addColumn('number', 'Ganancia$');          
          <%
          
            if(session.getAttribute("usuario") == null){
                response.setHeader("Refresh", "3;url=index.jsp");

            }else{            
                try{

                    DataPerfil dp = (DataPerfil)session.getAttribute("usuario");
                    DataEstadistica de = ip.obtenerEstadisticaLINE(dp.getNick());

                    if(de != null){

                        for(int i = de.getDatosX().size() - 1; i >= 0; i--){

                            %>                
        data.addRows([
                ['<%= de.getDatosX().get(i) %>', <%= de.getDatosY().get(i) %>]
            ]);          
    
        var options = {'title':'Ganancias mensules totales de <%= dp.getNick() %>.',
                       'width':800,
                       'height':350};          
//        var data = google.visualization.arrayToDataTable([
//          ['Year', 'Sales', 'Expenses'],
//          ['2004',  1000,      400],
//          ['2005',  1170,      460],
//          ['2006',  660,       1120],
//          ['2007',  1030,      540]
//        ]);

        var chart = new google.visualization.LineChart(document.getElementById('line'));
        chart.draw(data, options);
        
                            <%
                        }
                    }   

                }catch(Exception e){

                    dataEstadistica = dataEstadistica.concat(e.getMessage());

                } 
            }
        %>
      }
    </script>
    
</head>

<body>
        <jsp:include page="tplay_header.jsp"/>
        <jsp:include page="tplay_nav_visitante.jsp"/>
      
        <%@page contentType = "text/html" session = "true"%>
        
	<section id="contenido">
     
		<section id="graficas">

                    <%= dataEstadistica %>
                    <section class="graf" id="pie">   

                    </section>
                    <section class="graf" id="line">
                        
                    </section>

		</section>
	
	</section>
	
        <jsp:include page="tplay_footer.jsp"/>
        
</body>
</html>
